package com.examine.action;

import com.alibaba.fastjson.JSON;
import com.examine.bean.AccessApplication;
import com.examine.bean.User;
import com.examine.bean.UserReplenish;
import com.examine.serviceImpl.AccessApplicationServiceImpl;
import com.examine.serviceImpl.UserReplenishServiceImpl;
import com.examine.serviceImpl.UserServiceImpl;
import com.examine.utils.DateUtil;
import com.examine.utils.StrResponse;
import com.examine.utils.UuidUtil;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.commons.lang3.StringUtils;

import java.util.LinkedHashMap;

public class UserReplenishJsonAction extends ActionSupport {
    private LinkedHashMap mymp;
    private UserReplenishServiceImpl userReplenishService;
    private UserReplenish userReplenish;

    public LinkedHashMap getModelMap() {
        return mymp;
    }
    public void setModelMap(LinkedHashMap mymp) {
        this.mymp = mymp;
    }


    public String addUserReplenish(){
        userReplenish = JSON.parseObject(StrResponse.getStrResponse(), UserReplenish.class);

        if(StringUtils.isEmpty(userReplenish.getId())){
            mymp = StrResponse.error("用户ID不能为空");
            return ERROR;
        }

        userReplenish.setCreateTime(DateUtil.getCurrentTime());


        userReplenishService = new UserReplenishServiceImpl();
        int count = userReplenishService.insertSelective(userReplenish);
        if (count == 0){
            mymp = StrResponse.error("添加用户补充信息失败");
            return ERROR;
        }
        mymp = StrResponse.success("添加用户补充信息成功");
        return SUCCESS;
    }

    public String userClassGradeInfo(){
        userReplenish = JSON.parseObject(StrResponse.getStrResponse(), UserReplenish.class);

        userReplenishService = new UserReplenishServiceImpl();
        UserReplenish userReplenish1 = userReplenishService.userClassGradeInfo(userReplenish);

        if (userReplenish1 == null){
            mymp = StrResponse.error("查询用户信息失败",userReplenish1);
            return ERROR;
        }

        mymp = StrResponse.success("查询用户信息成功",userReplenish1);

        return SUCCESS;
    }

}
